<template>
  <view class="inbound-container">
    <!-- 页面头部 -->
    <view class="page-header">
      <text class="page-title">入库管理</text>
      <text class="page-subtitle">Inbound Management</text>
    </view>

    <!-- 功能按钮区域 -->
    <view class="action-buttons">
      <button class="action-btn primary" @click="handleNewInbound">
        <uni-icons type="plus" size="16" color="#fff"></uni-icons>
        <text>新建入库</text>
      </button>
      <button class="action-btn secondary" @click="handleScan">
        <uni-icons type="scan" size="16" color="#007AFF"></uni-icons>
        <text>扫码入库</text>
      </button>
    </view>

    <!-- 统计卡片 -->
    <view class="stats-cards">
      <view class="stats-card">
        <view class="stats-number">{{ todayCount }}</view>
        <view class="stats-label">今日入库</view>
      </view>
      <view class="stats-card">
        <view class="stats-number">{{ pendingCount }}</view>
        <view class="stats-label">待处理</view>
      </view>
      <view class="stats-card">
        <view class="stats-number">{{ completedCount }}</view>
        <view class="stats-label">已完成</view>
      </view>
    </view>

    <!-- 快速操作 -->
    <view class="quick-actions">
      <view class="section-title">
        <text>快速操作</text>
      </view>
      <view class="action-grid">
        <view class="action-item" @click="handlePreInbound">
          <uni-icons type="compose" size="24" color="#17a2b8"></uni-icons>
          <text>预入库</text>
        </view>
<!--        <view class="action-item" @click="handleMaterialInbound">
          <uni-icons type="box" size="24" color="#007AFF"></uni-icons>
          <text>物料入库</text>
        </view>-->
        <view class="action-item" @click="handleProductInbound">
          <uni-icons type="gift" size="24" color="#28a745"></uni-icons>
          <text>成品入库</text>
        </view>
        <view class="action-item" @click="handleMiscInbound">
          <uni-icons type="download" size="24" color="#e83e8c"></uni-icons>
          <text>其他入库</text>
        </view>
        <view class="action-item" @click="handleReturnInbound">
          <uni-icons type="undo" size="24" color="#ffc107"></uni-icons>
          <text>退货入库</text>
        </view>
        <view class="action-item" @click="handleTransferManagement">
          <uni-icons type="loop" size="24" color="#6f42c1"></uni-icons>
          <text>调拨管理</text>
        </view>
        <view class="action-item" @click="handlePurchaseInbound">
          <uni-icons type="shop" size="24" color="#fd7e14"></uni-icons>
          <text>采购入库</text>
        </view> 
       <!-- <view class="action-item" @click="handleProductInboundNew">
          <uni-icons type="gift" size="24" color="#20c997"></uni-icons>
          <text>成品入库(新版)</text>
        </view> -->
        
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'InboundIndex',
  data() {
    return {
      todayCount: 0,
      pendingCount: 0,
      completedCount: 0,
      recentRecords: [         
      ]
    }
  },
  
  onLoad() {
    this.loadInboundData()
  },
  
  methods: {
    // 加载入库数据
    loadInboundData() {
      // 这里可以调用API获取真实的入库数据
      
    },
    
    // 新建入库
    handleNewInbound() {
      uni.showToast({
        title: '新建入库功能',
        icon: 'none'
      })
    },
    
    // 扫码入库
    handleScan() {
      uni.showToast({
        title: '扫码入库功能',
        icon: 'none'
      })
    },
    
    // 物料入库
    handleMaterialInbound() {
      uni.showToast({
        title: '物料入库功能',
        icon: 'none'
      })
    },
    
    // 成品入库
    handleProductInbound() {
      uni.navigateTo({
        url: '/pages/app/inbound/product',
        success: () => {},
        fail: (err) => {
          console.error('跳转到成品入库页面失败:', err)
          uni.showToast({
            title: '页面跳转失败',
            icon: 'none'
          })
        }
      })
    },

    // 其他入库
    handleMiscInbound() {
      uni.navigateTo({
        url: '/pages/app/inbound/miscRecpt/index',
        success: () => {},
        fail: (err) => {
          console.error('跳转到其他入库页面失败:', err)
          uni.showToast({
            title: '页面跳转失败',
            icon: 'none'
          })
        }
      })
    },

    // 预入库（独立页面）
    handlePreInbound() {
      uni.navigateTo({
        url: '/pages/app/inbound/pre',
        success: () => {},
        fail: (err) => {
          console.error('跳转到预入库流程页面失败:', err)
          uni.showToast({
            title: '页面跳转失败',
            icon: 'none'
          })
        }
      })
    },
    
    // 退货入库
    handleReturnInbound() {
      uni.showToast({
        title: '退货入库功能',
        icon: 'none'
      })
    },
    
    // 调拨管理
    handleTransferManagement() {
      uni.showActionSheet({
        itemList: ['调拨发出', '调拨接收'],
        success: (res) => {
          if (res.tapIndex === 0) {
            // 调拨发出
            uni.navigateTo({
              url: '/pages/app/transfer/send',
              fail: (err) => {
                console.error('跳转到调拨发出页面失败:', err)
                uni.showToast({
                  title: '页面跳转失败',
                  icon: 'none'
                })
              }
            })
          } else if (res.tapIndex === 1) {
            // 调拨接收
            uni.navigateTo({
              url: '/pages/app/transfer/receive',
              fail: (err) => {
                console.error('跳转到调拨接收页面失败:', err)
                uni.showToast({
                  title: '页面跳转失败',
                  icon: 'none'
                })
              }
            })
          }
        }
      })
    },
    
    // 采购入库
    handlePurchaseInbound() {
      uni.navigateTo({
        url: '/pages/app/inbound/purchase/index',
        success: () => {},
        fail: (err) => {
          console.error('跳转到采购入库页面失败:', err)
          uni.showToast({
            title: '页面跳转失败',
            icon: 'none'
          })
        }
      })
    },
    
    // 成品入库(新版) 测试入口
    handleProductInboundNew() {
      uni.navigateTo({
        url: '/pages/app/inbound/product_new',
        success: () => {},
        fail: (err) => {
          console.error('跳转到成品入库(新版)失败:', err)
          uni.showToast({
            title: '页面跳转失败',
            icon: 'none'
          })
        }
      })
    },
    
    // 查看全部记录
    handleViewAll() {
      uni.showToast({
        title: '查看全部记录',
        icon: 'none'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.inbound-container {
  padding: 20rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
}

.page-header {
  text-align: center;
  margin-bottom: 30rpx;
  
  .page-title {
    display: block;
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 10rpx;
  }
  
  .page-subtitle {
    font-size: 24rpx;
    color: #666;
  }
}

.action-buttons {
  display: flex;
  gap: 20rpx;
  margin-bottom: 30rpx;
  
  .action-btn {
    flex: 1;
    height: 80rpx;
    border-radius: 40rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10rpx;
    font-size: 28rpx;
    border: none;
    
    &.primary {
      background: linear-gradient(135deg, #007AFF 0%, #5AC8FA 100%);
      color: #fff;
    }
    
    &.secondary {
      background: #fff;
      color: #007AFF;
      border: 2rpx solid #007AFF;
    }
  }
}

.stats-cards {
  display: flex;
  gap: 20rpx;
  margin-bottom: 30rpx;
  
  .stats-card {
    flex: 1;
    background: #fff;
    padding: 30rpx 20rpx;
    border-radius: 12rpx;
    text-align: center;
    box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
    
    .stats-number {
      font-size: 48rpx;
      font-weight: bold;
      color: #007AFF;
      margin-bottom: 10rpx;
    }
    
    .stats-label {
      font-size: 24rpx;
      color: #666;
    }
  }
}

.quick-actions, .recent-records {
  background: #fff;
  border-radius: 12rpx;
  padding: 30rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;
  
  text {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
  }
  
  .more-btn {
    font-size: 24rpx;
    color: #007AFF;
  }
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20rpx;
  
  .action-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30rpx 20rpx;
    background: #f8f9fa;
    border-radius: 12rpx;
    gap: 10rpx;
    
    text {
      font-size: 24rpx;
      color: #333;
    }
  }
}

.record-list {
  .record-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 0;
    border-bottom: 1rpx solid #f0f0f0;
    
    &:last-child {
      border-bottom: none;
    }
    
    .record-info {
      flex: 1;
      
      .record-title {
        display: block;
        font-size: 28rpx;
        color: #333;
        margin-bottom: 5rpx;
      }
      
      .record-desc {
        display: block;
        font-size: 24rpx;
        color: #666;
        margin-bottom: 5rpx;
      }
      
      .record-time {
        font-size: 22rpx;
        color: #999;
      }
    }
    
    .record-status {
      padding: 8rpx 16rpx;
      border-radius: 20rpx;
      font-size: 22rpx;
      
      &.completed {
        background: #d4edda;
        color: #155724;
      }
      
      &.pending {
        background: #fff3cd;
        color: #856404;
      }
    }
  }
}
</style>
